package cn.edu.ren.controller;

import cn.edu.ren.pojo.User;
import cn.edu.ren.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @PackageName: cn.edu.ren.controller
 * @ClassName: UserController
 * @Description:
 * @author: RZS
 * @date: 2021/5/20  0:22
 */
@RestController
@RequestMapping("/mybatis")
public class UserController {
    
    @Autowired
    private IUserService userService;

    @GetMapping("select_all")
    public List<User> findAll(){
        return userService.findAll();
    }

    @PostMapping("/add")
    public List<User> addUser(User User){
        System.err.println(User.toString());
        userService.addUser(User);
        return findAll();
    }

    @PostMapping("/update")
    public List<User> changeByUsername(String username, Integer id){
        userService.changeByUsername(username, id);
        return findAll();
    }

    @GetMapping("/delete/{id}")
    public List<User> remove(@PathVariable Integer id){
        userService.removeById(id);
        return findAll();
    }
}
